/**
 * Created by Administrator on 2016/7/15.
 */
"use strict";
swan_pc
    .controller("LookOverListShowController",function($q,$scope,$rootScope,TimeExchange,GetAccountInfo){
        //console.log("LookOverListShow:"+$scope.userClipList);
        //console.log("LookOverListShowController:"+$scope.$parent.userClipList);
        $scope.intputClipName="";
        $scope.userClipListFilter=[];
        var def=$q.defer();
        var pro=def.promise;
        GetAccountInfo.get(function(result){
                $scope.presentAccountInfo=result;
                $scope.MyId=$scope.presentAccountInfo.id;
                console.log($scope.MyId);
                def.resolve();
            },
            function(result){
                def.reject();
            })
        pro.then(
            function(){
                $scope.loadAll();
            }
        )
        $scope.loadAll=function() {
            angular.forEach($scope.$parent.userClipList, function (data, index, array) {
                if (data.bookerId == "" || data.bookerId == null) {
                    //console.log(data.status + " " + data.level);
                    if (data.status == "CONFIRM" && data.level == "主事项") {
                        $scope.userClipListFilter.push(data);
                    }
                } else if (data.bookerId == $scope.MyId) {
                    $scope.userClipListFilter.push(data);
                }
            })
        }
        $scope.TimeShow=function(time){
            if(time==null){
                return "";
            }
            var date=new Date(time);
            var timer=date.toString();
            timer=TimeExchange.StringtoLocalTime(timer);
            //console.log("clipserch "+time + " " + " "+date + " "+ timer);
            return timer;
        };
        $scope.$watch(function(){
                return $scope.$parent.userClipList;
            },
            function(newValue,oldValue, scope){
                if($rootScope.toState.name="lookoveruserclip") {
                    //console.log("list change!!!!");
                    if($scope.MyId!=undefined){
                        $scope.userClipListFilter=[];
                        $scope.loadAll();
                    }
                }
            });
        $scope.$watch(function(){
            return $scope.$parent.inputClipName;
        },
        function(newValue,oldValue,scope){
            if($rootScope.toState.name="lookoveruserclip"){
                //console.log("inputClipNameChanged:"+$scope.$parent.inputClipName);
                $scope.inputClipName=$scope.$parent.inputClipName;
            }
        })
        $scope.BookClipListCheck=function(clipStatus,clipBookerId){
            var className="";
            if(clipBookerId==null || clipBookerId==""){
                return "";
            }else{
                if(clipStatus=="DRAFT"){
                    className="draftColor";
                    return className;
                }else if(clipStatus="CONFIRM"){
                    className="confirmColor";
                    return className;
                }else{
                    className="closedColor";
                    return className;
                }
            }
        }
    })